package main

import (
	"log"
	"weboffice-go-sdk/examples/internal/demo"
	"weboffice-go-sdk/weboffice"
)

type TestProvider struct {
	demo *demo.Provider
}

func (t *TestProvider) GetFile(ctx weboffice.Context, fileID string) (*weboffice.GetFileReply, error) {
	return t.demo.GetFile(ctx, fileID)
}

func (t *TestProvider) GetFileDownload(ctx weboffice.Context, fileID string) (*weboffice.GetFileDownloadReply, error) {
	return t.demo.GetFileDownload(ctx, fileID)
}

func (t *TestProvider) GetFilePermission(_ weboffice.Context, _ string) (*weboffice.GetFilePermissionReply, error) {
	return &weboffice.GetFilePermissionReply{
		Comment:  1,
		Copy:     1,
		Download: 1,
		History:  0,
		Print:    1,
		Read:     1,
		Rename:   0,
		SaveAs:   0,
		Update:   0,
		UserId:   "anonymous",
	}, nil
}

func main() {
	provider := &TestProvider{
		demo: demo.NewProvider(),
	}
	server := weboffice.NewServer(weboffice.Config{
		BaseProvider: provider,
		Logger:       weboffice.DefaultLogger(),
		Prefix:       "/weboffice-go-sdk/",
	})
	server.Router().GET("/download", provider.demo.DownloadFile)

	if err := server.Run(":8080"); err != nil {
		log.Fatal(err)
	}
}
